<template>
  <z-modal
    :width="800"
    v-bind="modalOption"
    :okText="false"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model layout="horizontal" labelAlign="right" ref="ruleForm" :label-col="labelCol" :wrapper-col="wrapperCol" :model="form" :rules="validatorRules">
        <a-form-model-item label="商机名称" prop="businessName">
          <a-input v-model.trim="form.businessName" placeholder="请输入商机名称" :disabled="disableSubmit"></a-input>
        </a-form-model-item>
        <a-form-model-item label="项目" prop="productName">
		  <a-input-search v-model="form.productName" readOnly @search="onSearchProduct" placeholder="">
		  			  <a-button slot="enterButton">选择项目</a-button>
		  </a-input-search>
        </a-form-model-item>
		<a-form-model-item label="客户" prop="customerName">
		  <a-input-search v-model="form.customerName" readOnly @search="onSearchCustomer" placeholder="">
			  <a-button slot="enterButton">选择客户</a-button>
		  </a-input-search>
		</a-form-model-item>
        <a-form-model-item label="消息来源" prop="source">
          <z-dict-select-tag v-model="form.source"  dictCode="news_source" placeholder="请选择消息来源" :disabled="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item label="商机归属人" prop="ownerUserId">
          <ZSelectUserByDep :multi="false" v-model="form.ownerUserId" />
        </a-form-model-item>
        <a-form-model-item label="预估合同总额" prop="money">
          <a-input-number v-model="form.money" placeholder="请输入预估合同总额" style="width: 100%" :disabled="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item label="销售阶段" prop="statusId">
          <z-dict-select-tag v-model="form.statusId"  dictCode="business_status" placeholder="销售阶段" :disabled="disableSubmit"/>
        </a-form-model-item>
        <a-form-model-item label="跟进公司" prop="companyName">
          <a-input v-model.trim="form.companyName" placeholder="请输入跟进公司" :disabled="disableSubmit"></a-input>
        </a-form-model-item>
		<a-form-model-item label="有无合同" prop="isContract">
		  <z-dict-select-tag v-model="form.isContract"  dictCode="is_contract" placeholder="有无合同" :disabled="disableSubmit" />
		</a-form-model-item>
        <a-form-model-item label="备注" prop="remark">
          <a-textarea v-model.trim="form.remark" :maxLength=200 placeholder="请输入备注" :disabled="disableSubmit"></a-textarea>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
	<SelectCustomerModal ref="selectModal" @ok="selectOK"></SelectCustomerModal>
	<SelectProductModal ref="selectModal2" @ok="selectOK2"></SelectProductModal>
  </z-modal>
</template>

<script>
import ModalFormMixin from '@/mixins/ModalFormMixin'
import ZDictSelectTag from '@/components/dict/ZDictSelectTag'
import ZSelectUserByDep from '@/components/zzbiz/ZSelectUserByDep'
import SelectCustomerModal from '@/pages/crm/customer/modules/SelectCustomerModal'
import SelectProductModal from '@/pages/crm/product/modules/SelectProductModal'
export default {
  name: 'CrmBusinessModal',
  mixins: [ModalFormMixin],
  components: {
    ZDictSelectTag,
    ZSelectUserByDep,
    SelectCustomerModal,
	SelectProductModal
  },
  data() {
    return {
      validatorRules: {
        businessName: [
            { required: true, message: '请输入商机名称!'},
          ],
        },
      url: {
        add: "/business/add",
        edit: "/business/edit",
        queryById: "/business/queryById"
      }
    }
  },
  methods: {
    addAfter() {
    },
	onSearchCustomer() {
	  this.$refs.selectModal.showModal()
	},
	onSearchProduct() {
	  this.$refs.selectModal2.showModal()
	},
	selectOK(rows, idstr) {
	  if(!rows){
	    this.form.customerId = ''
	    this.form.customerName = ''
	  }else{
	    let row = rows[0]
	    this.form.customerId = row.id
	    this.form.customerName = row.customerName
	  }
	  this.form = Object.assign({},this.form)
	},
	selectOK2(rows, idstr) {
	  if(!rows){
	    this.form.productId = ''
	    this.form.productName = ''
	  }else{
	    let row = rows[0]
	    this.form.productId = row.id
	    this.form.productName = row.name
	  }
	  this.form = Object.assign({},this.form)
	}
  }
}
</script>
